package cn.com.zcode.email.dao;

import java.io.File;
import java.util.Map;
import java.util.Set;

import cn.com.zcode.core.scan.FileFilter;
import cn.com.zcode.core.scan.ScanFilter;
import cn.com.zcode.core.scan.Scanner;
import cn.com.zcode.core.xml.XmlReader;
import cn.com.zcode.email.model.XmlEmailTemp;

public class EmailDaoImpl implements EmailDao {
	private static Scanner scanner = new Scanner();
	private static ScanFilter<File> filter = new FileFilter(".xml");
	private static XmlReader reader = new XmlReader();
	private Map<String, XmlEmailTemp> map = null;
	private String packages;

	@Override
	public XmlEmailTemp getTemplate(String temKey) {
		if (map == null) {
			Set<File> set = scanner.scan(filter, packages);
			map = reader.read(set, XmlEmailTemp.class);
		}

		return map.get(temKey);
	}

	public String getPackages() {
		return packages;
	}

	public void setPackages(String packages) {
		this.packages = packages;
	}

}
